<?php
/**
 * @Author: Ron Chen
 * @Date:   2017-03-25 22:25:43
 * @Last Modified by:   Ron Chen
 * @Last Modified time: 2017-03-26 12:20:12
 */
namespace app\models;

use Yii;

/**
 * 被保险人
 */
class InsurancePolicyInsured extends \yii\db\ActiveRecord
{
    const INSURANCE_SUCCESS = 'ok';

    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'insurance_policy_insured';
    }
    
    /**
     * 初始化用户操作
     */
    public static function initRecord($param){
    	$policy_id = isset($param["policy_id"]) ? $param["policy_id"] : '';
    	
		$userInfo = new static();
        $userInfo->policy_id   = $param['policy_id'];
        $userInfo->create_time = date('Y-m-d H:i:s');
        $userInfo->status = self::INSURANCE_SUCCESS;
	   
        if (isset($param['occupation_code']) && $param['occupation_code']) {
            $userInfo->occupation_code = $param['occupation_code'];
        }
        if (isset($param['insured_id']) && $param['insured_id']) {
            $userInfo->insured_id = $param['insured_id'];
        }
    	if (isset($param['insured_name']) && $param['insured_name']) {
    		$userInfo->insured_name = $param['insured_name'];
    	}
    	if (isset($param['insured_type']) && $param['insured_type']) {
    		$userInfo->insured_type = $param['insured_type'];
    	}
        if (isset($param['id_type']) && $param['id_type']) {
            $userInfo->id_type = $param['id_type'];
        }
    	if (isset($param['id_number']) && $param['id_number']) {
    		$userInfo->id_number = $param['id_number'];
    	}
    	if (isset($param['birth_date']) && $param['birth_date']) {
    		$userInfo->birth_date = $param['birth_date'];
    	}
    	if (isset($param['mobile']) && $param['mobile']) {
    		$userInfo->mobile = $param['mobile'];
    	}
        if (isset($param['address']) && $param['address']) {
            $userInfo->address = $param['address'];
        }
        if (isset($param['postcode']) && $param['postcode']) {
            $userInfo->postcode = $param['postcode'];
        }
    	if (isset($param['email']) && $param['email']) {
    		$userInfo->email = $param['email'];
    	}
        if (isset($param['gender']) && $param['gender']) {
            $userInfo->gender = $param['gender'];
        }
        if (isset($param['benificial_type']) && $param['benificial_type']) {
            $userInfo->benificial_type = $param['benificial_type'];
        }
        if (isset($param['policy_holder_relation']) && $param['policy_holder_relation']) {
            $userInfo->policy_holder_relation = $param['policy_holder_relation'];
        }
        if (isset($param['premium_currency']) && $param['premium_currency']) {
            $userInfo->premium_currency = $param['premium_currency'];
        }

    	if ($userInfo->save()) {
    		return $userInfo->attributes['id'];
    	}
    	return false;
    }
    
}